package net.entelijan.cobean.examples.showcase.bind.text;

import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;

import net.entelijan.cobean.examples.util.ExamplesUtil;
import net.entelijan.scf.DefaultShowcasePanel;
import net.miginfocom.swing.MigLayout;

public class TextPanel extends DefaultShowcasePanel {

	private JTextField nameTextField = new JTextField();
	private JTextField birthdayTextField = new JTextField();
	private JTextField idTextField = new JTextField();

	private JTextComponent nameFailureTextField = createFailureComponent();
	private JTextComponent birthdayFailureTextField = createFailureComponent();
	private JTextComponent idFailureTextField = createFailureComponent();

	private JButton resetButton = new JButton("Reset");
	private JButton showObjectButton = new JButton("Show Model");
	private JButton uppercaseButton = new JButton("Uppercase");
	private JButton lowercaseButton = new JButton("Lowercase");

	private static final long serialVersionUID = 1L;

	public TextPanel() {
		super();
		// Layout the components
		setLayout(new MigLayout());
		add(new JLabel("Name"), "w 150");
		add(nameTextField, "w 200:200:200");
		add(nameFailureTextField, "w max, grow, wrap");
		add(new JLabel("Birthday"), "w 150");
		add(birthdayTextField, "w 200:200:200");
		add(birthdayFailureTextField, "w max, grow, wrap");
		add(new JLabel("ID"), "w 150");
		add(idTextField, "w 200:200:200");
		add(idFailureTextField, "w max, grow, wrap");
		add(new JPanel(), "span 3, h max, grow, w max, wrap");
		add(ExamplesUtil.createButtonsPanel(100, this.resetButton,
				this.showObjectButton, this.uppercaseButton,
				this.lowercaseButton), "span 3");
	}

	// Create a failure component
	private JTextComponent createFailureComponent() {
		JTextField re = new JTextField();
		re.setEditable(false);
		re.setForeground(Color.RED);
		re.setFocusable(false);
		re.setBorder(null);
		return re;
	}

	// Setters and getters for all components

	public JButton getShowObjectButton() {
		return showObjectButton;
	}

	public void setShowObjectButton(JButton showSelectedButton) {
		this.showObjectButton = showSelectedButton;
	}

	public JTextField getNameTextField() {
		return nameTextField;
	}

	public void setNameTextField(JTextField nameTextField) {
		this.nameTextField = nameTextField;
	}

	public JTextField getBirthdayTextField() {
		return birthdayTextField;
	}

	public void setBirthdayTextField(JTextField birthdayTextField) {
		this.birthdayTextField = birthdayTextField;
	}

	public JTextField getIdTextField() {
		return idTextField;
	}

	public void setIdTextField(JTextField idTextField) {
		this.idTextField = idTextField;
	}

	public JButton getUppercaseButton() {
		return uppercaseButton;
	}

	public void setUppercaseButton(JButton uppercaseButton) {
		this.uppercaseButton = uppercaseButton;
	}

	public JButton getLowercaseButton() {
		return lowercaseButton;
	}

	public void setLowercaseButton(JButton lowercaseButton) {
		this.lowercaseButton = lowercaseButton;
	}

	public JTextComponent getNameFailureTextField() {
		return nameFailureTextField;
	}

	public void setNameFailureTextField(JTextComponent nameFailureTextField) {
		this.nameFailureTextField = nameFailureTextField;
	}

	public JTextComponent getBirthdayFailureTextField() {
		return birthdayFailureTextField;
	}

	public void setBirthdayFailureTextField(
			JTextComponent birthdayFailureTextField) {
		this.birthdayFailureTextField = birthdayFailureTextField;
	}

	public JTextComponent getIdFailureTextField() {
		return idFailureTextField;
	}

	public void setIdFailureTextField(JTextField idFailureTextField) {
		this.idFailureTextField = idFailureTextField;
	}

	public JButton getResetButton() {
		return resetButton;
	}

	public void setResetButton(JButton resetButton) {
		this.resetButton = resetButton;
	}

}
